#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys, array

INPUT_DIR = '.'
OUTPUT_DIR = '.'
INPUT_FILE = 'input.jpg'
OUTPUT_FILE = 'output.jpg'

# Convert a file into an array of bytes.
# Get the file path.
filepath = os.path.join(INPUT_DIR, INPUT_FILE)
try:
    # Conversion.
    input = array.array('B', open(filepath).read()).tolist()
except IOError, ex:
    print ex
    sys.exit(0)

# Convert an array of bytes into a file.
# Get the destination file path.
result = os.path.join(OUTPUT_DIR, OUTPUT_FILE)
# Conversion.
array.array('B', input).tofile(open(result, 'w'))
